define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    
    
    
    // require("core/widgets/input/rkFcbkUser");
    $.widget('rk.groupAddMember', $.rk.oaDialogCtrl, {
        _create:function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;
            var temp = require("oa/tmpl/group/content/tpl_group_content_member_add.tpl");
            elem.html(rk.templateText(temp));
            elem.find("[act='group_member_add_text']").multipeopleselector({
                position: {
                    my: 'left top+2'
                }
            });
            //group_member_add_text
            me._listeners();
        },
        _listeners:function(){
        },
        _init:function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;
            var footer = me.getFooter();
            me.getBtn('ok').on('click', $.proxy(me.okClicked, me));
            footer.find('*[act="cancel"]').on('click', $.proxy(me.cancelClicked, me));
        },
        okClicked: function () {
            var me = this;
            var elem = me.element;
            me._doSave();//保存
        },
        cancelClicked: function () {
            var me = this;
            var elem = me.element;
            me.closeMe();//关闭
        },
        _doSave: function () {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            //var users =elem.find("[act='group_member_add_text']").rkFcbkUser('getUsers');
            //elem.find("[act='group_member_add_text']").rkFcbkUser('readonly');
            var users = elem.find("[act='group_member_add_text']").multipeopleselector("val");
            var userIds = "";
            $.each(users, function (i, user) {
                userIds += "," + user.value;
            });
            userIds = userIds.substr(1,userIds.length - 1);
            me.getBtn('ok').beLoading();
            rk.post("/json/oa_group/members-join.action",{uidList:userIds,gid:opt.gid},function(json){
                if(json.status === 0){
                    //刷新列表
                    var content = rk.oa.getContent();
                    var tab = content.find("#group_content_member_tab");
                    if(tab && tab.find("[act='group_member_list_table']")){
                        require.async(["./groupContentMemberTabCtrl"],function(){
                            tab.groupContentMemberTabCtrl({gid:opt.gid});
                        });
                    }
                    me.closeMe();
                    rk.noticeSuccess(rk.i18n('COLLEAGUE_OPERATE_SUCCESS'));
                }else{
                    me.getBtn('ok').beLoading('delay');
                    // elem.find("[act='group_member_add_text']").rkFcbkUser('readonly',false);
                    rk.noticeError(rk.i18n('COLLEAGUE_SYSTEM_ERROR'));
                }
            });
        }
    });
});